package com.iris.live.services.common;

import com.iris.live.services.data.models.Lsh消息Model;
import com.iris.live.services.data.repositories.Lsh消息Repository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.sql.Timestamp;
import java.util.Date;

/**
 * 原理基于springMVC注解扫描，启动程序时@PostConstruct声明init方法注入
 * Created by hyp on 2016/11/24.
 */
@Component
public class LshMsgUtils {

    private static LshMsgUtils lshMsgUtils;
    @Autowired
    private Lsh消息Repository lsh消息Repository;

    /**
     * 异步产生message
     *
     * @param sendPermit
     * @param sendUser
     * @param recPermit
     * @param recUser
     * @param msgType
     * @param content
     * @param updateUser
     * @param mobile
     * @return
     */
    @Async
    public static Lsh消息Model getLshMsg(String sendPermit, String sendUser, String recPermit, String recUser, String msgType, String content,
                                       String updateUser, String mobile) {
        Timestamp ts = DateFormatUtils.getFormatTimestamp("yyyy-MM-dd HH:mm:ss", new Date());
        //Date dt = DateFormatUtils.getFormatDate("yyyy-MM-dd", new Date());
        Lsh消息Model l = new Lsh消息Model();
        l.set发送人(sendUser);
        l.set发送许可(sendPermit);
        l.set接收许可(recPermit);
        l.set接收人(recUser);
        l.set消息分类(msgType);
        l.set消息内容(content);
        l.set是否删除("否");
        l.set更新账号(updateUser);
        l.set消息创建时间(ts);
        l.set更新时间(ts);
        l.set电话号码(mobile);
        l.setRead(false);
        return lshMsgUtils.lsh消息Repository.save(l);
    }


    /**
     * 异步产生message(包含附属类型)
     *
     * @param sendPermit
     * @param sendUser
     * @param recPermit
     * @param recUser
     * @param msgType
     * @param content
     * @param updateUser
     * @param mobile
     * @return
     */
    @Async
    public static Lsh消息Model getLshMsg(String sendPermit, String sendUser, String recPermit, String recUser, String msgType, String content,
                                       String updateUser, String mobile, String extType) {
        Timestamp ts = DateFormatUtils.getFormatTimestamp("yyyy-MM-dd HH:mm:ss", new Date());
        //Date dt = DateFormatUtils.getFormatDate("yyyy-MM-dd", new Date());
        Lsh消息Model l = new Lsh消息Model();
        l.set发送人(sendUser);
        l.set发送许可(sendPermit);
        l.set接收许可(recPermit);
        l.set接收人(recUser);
        l.set消息分类(msgType);
        l.set消息内容(content);
        l.set是否删除("否");
        l.set更新账号(updateUser);
        l.set消息创建时间(ts);
        l.set更新时间(ts);
        l.set电话号码(mobile);
        l.set附属Id类型(extType);
        l.setRead(false);
        return lshMsgUtils.lsh消息Repository.save(l);
    }


    /**
     * 异步产生message(包含附属类型,消息附属Id,消息备注,删除账号,创建时间)
     *
     * @param sendPermit
     * @param sendUser
     * @param recPermit
     * @param recUser
     * @param msgType
     * @param content
     * @param updateUser
     * @param mobile
     * @param extType
     * @param extId
     * @param remark
     * @param deleteAccount
     * @param createTime
     * @return
     */
    @Async
    public static Lsh消息Model getLshMsg(String sendPermit, String sendUser, String recPermit, String recUser, String msgType, String content,
                                       String updateUser, String mobile, String extType, String extId, String remark,
                                       String deleteAccount, Date createTime) {
        Timestamp ts = DateFormatUtils.getFormatTimestamp("yyyy-MM-dd HH:mm:ss", createTime);
        //Date dt = DateFormatUtils.getFormatDate("yyyy-MM-dd", new Date());
        Lsh消息Model l = new Lsh消息Model();
        l.set发送人(sendUser);
        l.set发送许可(sendPermit);
        l.set接收许可(recPermit);
        l.set接收人(recUser);
        l.set消息分类(msgType);
        l.set消息内容(content);
        l.set是否删除("否");
        l.set更新账号(updateUser);
        l.set消息创建时间(ts);
        l.set更新时间(ts);
        l.set电话号码(mobile);
        l.set附属Id类型(extType);
        l.set删除账号(deleteAccount);
        l.set消息附属Id(extId);
        l.set消息备注(remark);
        l.setRead(false);
        return lshMsgUtils.lsh消息Repository.save(l);
    }

    /**
     * 异步产生message(基本信息)
     *
     * @param sendPermit
     * @param sendUser
     * @param recPermit
     * @param recUser
     * @param content
     * @return
     */
    @Async
    public static Lsh消息Model getLshMsg(String sendPermit, String sendUser, String recPermit, String recUser, String content, String messageType) {
        Timestamp ts = DateFormatUtils.getFormatTimestamp("yyyy-MM-dd HH:mm:ss", new Date());
        //Date dt = DateFormatUtils.getFormatDate("yyyy-MM-dd", new Date());
        Lsh消息Model l = new Lsh消息Model();
        l.set发送人(sendUser);
        l.set发送许可(sendPermit);
        l.set接收许可(recPermit);
        l.set接收人(recUser);
        l.set消息内容(content);
        l.set是否删除("否");
        l.set消息创建时间(ts);
        l.set消息分类(messageType);
        l.setRead(false);
        return lshMsgUtils.lsh消息Repository.save(l);
    }

    /**
     * 异步产生message
     */
    @Async
    public static Lsh消息Model getLshMsg(String sendPermit, String sendUser, String receivePermit, String receiveUser,
                                       String msgType, String msgContent, String msgApdxId, String apdxIdType,
                                       String remark, java.sql.Date createTime, String isDel, String delUser,
                                       String updUser, Timestamp updTime, String cell, boolean isRead) {
        Lsh消息Model msgModel = new Lsh消息Model();
        msgModel.set发送许可(sendPermit);
        msgModel.set发送人(sendUser);
        msgModel.set接收许可(receivePermit);
        msgModel.set接收人(receiveUser);
        msgModel.set消息分类(msgType);
        msgModel.set消息内容(msgContent);
        msgModel.set消息附属Id(msgApdxId);
        msgModel.set附属Id类型(apdxIdType);
        msgModel.set消息备注(remark);
        msgModel.set消息创建时间(createTime);
        msgModel.set是否删除(isDel);
        msgModel.set删除账号(delUser);
        msgModel.set更新账号(updUser);
        msgModel.set更新时间(updTime);
        msgModel.set电话号码(cell);
        msgModel.setRead(isRead);
        return lshMsgUtils.getLsh消息Repository().save(msgModel);
    }

    /**
     * 异步产生message（包括附加消息）
     */
    @Async
    public static Lsh消息Model getLshMsg(String sendPermit, String sendUser, String receivePermit, String receiveUser,
                                       String msgType, String msgContent, String msgApdxId, String apdxIdType,
                                       String remark, Date createTime, String isDel, String delUser,
                                       String updUser, Timestamp updTime, String cell, boolean isRead,String additionalMessage) {
        Lsh消息Model msgModel = new Lsh消息Model();
        msgModel.set发送许可(sendPermit);
        msgModel.set发送人(sendUser);
        msgModel.set接收许可(receivePermit);
        msgModel.set接收人(receiveUser);
        msgModel.set消息分类(msgType);
        msgModel.set消息内容(msgContent);
        msgModel.set消息附属Id(msgApdxId);
        msgModel.set附属Id类型(apdxIdType);
        msgModel.set消息备注(remark);
        msgModel.set消息创建时间(createTime);
        msgModel.set是否删除(isDel);
        msgModel.set删除账号(delUser);
        msgModel.set更新账号(updUser);
        msgModel.set更新时间(updTime);
        msgModel.set电话号码(cell);
        msgModel.setRead(isRead);
        msgModel.setAdditionalMessage(additionalMessage); // 附加消息
        return lshMsgUtils.getLsh消息Repository().save(msgModel);
    }

    public Lsh消息Repository getLsh消息Repository() {
        return lsh消息Repository;
    }

    public void setLsh消息Repository(Lsh消息Repository lsh消息Repository) {
        this.lsh消息Repository = lsh消息Repository;
    }

    @PostConstruct
    public void init() {
        lshMsgUtils = this;
        lshMsgUtils.lsh消息Repository = this.lsh消息Repository;

    }
}
